﻿/*
 * Created by SharpDevelop.
 * User: rogerio
 * Date: 19/12/2009
 * Time: 10:19
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using ComponentFactory.Krypton.Toolkit;
using System.Collections.Generic;

namespace csharp.rad.general 
{
	/// <summary>
	/// Description of Product.
	/// </summary>
	public class Product : csharp.common.DefaultClass, csharp.common.IClass
	{
		#region Declaration variables
		private String _name;
	    private String _short_name;
	    private String _bar_code;
	    private String _code;
	    private String _unit1;
	    private String _unit2;
	    private String _unit3;
	    private String _conversion1;
	    private String _conversion2;
	    private String _service;
	    private String _rent;
	    private String _service_order;
	    private String _image;
	    private String _stock_min;
	    private String _stock_max;
	    private String _weight;
	    private String _duration_time;
	    private String _fiscal_nature;
	    private String _last_purchase;
	    private String _purchase_price;
	    private String _sale_price1;
	    private String _sale_price2;
	    private String _sale_price3;
	    private String _nature;
	    private String _control_nserie;
	    private String _accept_discount;
	    private String _accept_fraction;
	    private String _user_bars;
	    private String _active;
	    private String _register_date;
	    private String _alteration_date;
	    private String _ncm_code;
	    private String _nbm_code;
	    private String _obs;
	    private String _application;
	    private String _product_group_id;
	    private String _product_sub_group_id;
	    private String _product_mark_id;
	    private String _product_section_id;
	    private String _product_type_id;
	    private String _company_id;
	    private String _warehouse_id;
	    private String _en_tributary_situation_id;
	    private String _ex_tributary_situation_id;
	    private String _vendor_id1;
	    private String _vendor_id2;
	    private String _vendor_id3;
		#endregion
		public Product()
		{
			gsql.table = "common.product";
			_sequence  = "common.product_product_id_seq";
			
			clear();
		}
		
		#region methods get and set
		public string Name {
			get { return _name; }
			set { _name = value; }
		}
		
		public string Short_name {
			get { return _short_name; }
			set { _short_name = value; }
		}
		
		public string Bar_code {
			get { return _bar_code; }
			set { _bar_code = value; }
		}
		
		public string Code {
			get { return _code; }
			set { _code = value; }
		}
		
		public string Unit1 {
			get { return _unit1; }
			set { _unit1 = value; }
		}
		
		public string Unit2 {
			get { return _unit2; }
			set { _unit2 = value; }
		}
		
		public string Unit3 {
			get { return _unit3; }
			set { _unit3 = value; }
		}
		
		public string Conversion1 {
			get { return _conversion1; }
			set { _conversion1 = value; }
		}
		
		public string Conversion2 {
			get { return _conversion2; }
			set { _conversion2 = value; }
		}
		
		public string Service {
			get { return _service; }
			set { _service = value; }
		}
		
		public string Rent {
			get { return _rent; }
			set { _rent = value; }
		}
		
		public string Service_order {
			get { return _service_order; }
			set { _service_order = value; }
		}
		
		public string Image {
			get { return _image; }
			set { _image = value; }
		}
		
		public string Stock_min {
			get { return _stock_min; }
			set { _stock_min = value; }
		}
		
		public string Stock_max {
			get { return _stock_max; }
			set { _stock_max = value; }
		}
		
		public string Weight {
			get { return _weight; }
			set { _weight = value; }
		}
		
		public string Duration_time {
			get { return _duration_time; }
			set { _duration_time = value; }
		}
		
		public string Fiscal_nature {
			get { return _fiscal_nature; }
			set { _fiscal_nature = value; }
		}
		
		public string Last_purchase {
			get { return _last_purchase; }
			set { _last_purchase = value; }
		}
		
		public string Purchase_price {
			get { return _purchase_price; }
			set { _purchase_price = value; }
		}
		
		public string Sale_price1 {
			get { return _sale_price1; }
			set { _sale_price1 = value; }
		}
		
		public string Sale_price2 {
			get { return _sale_price2; }
			set { _sale_price2 = value; }
		}
		
		public string Sale_price3 {
			get { return _sale_price3; }
			set { _sale_price3 = value; }
		}
		
		public string Nature {
			get { return _nature; }
			set { _nature = value; }
		}
		
		public string Control_nserie {
			get { return _control_nserie; }
			set { _control_nserie = value; }
		}
		
		public string Accept_discount {
			get { return _accept_discount; }
			set { _accept_discount = value; }
		}
		
		public string Accept_fraction {
			get { return _accept_fraction; }
			set { _accept_fraction = value; }
		}
		
		public string User_bars {
			get { return _user_bars; }
			set { _user_bars = value; }
		}
		
		public string Active {
			get { return _active; }
			set { _active = value; }
		}
		
		public string Register_date {
			get { return _register_date; }
			set { _register_date = value; }
		}
		
		public string Alteration_date {
			get { return _alteration_date; }
			set { _alteration_date = value; }
		}
		
		public string Ncm_code {
			get { return _ncm_code; }
			set { _ncm_code = value; }
		}
		
		public string Nbm_code {
			get { return _nbm_code; }
			set { _nbm_code = value; }
		}
		
		public string Obs {
			get { return _obs; }
			set { _obs = value; }
		}
		
		public string Application {
			get { return _application; }
			set { _application = value; }
		}
		
		public string Product_group_id {
			get { return _product_group_id; }
			set { _product_group_id = value; }
		}
		
		public string Product_sub_group_id {
			get { return _product_sub_group_id; }
			set { _product_sub_group_id = value; }
		}
		
		public string Product_mark_id {
			get { return _product_mark_id; }
			set { _product_mark_id = value; }
		}
		
		public string Product_section_id {
			get { return _product_section_id; }
			set { _product_section_id = value; }
		}
		
		public string Product_type_id {
			get { return _product_type_id; }
			set { _product_type_id = value; }
		}
		
		public string Company_id {
			get { return _company_id; }
			set { _company_id = value; }
		}
		
		public string Warehouse_id {
			get { return _warehouse_id; }
			set { _warehouse_id = value; }
		}
		
		public string En_tributary_situation_id {
			get { return _en_tributary_situation_id; }
			set { _en_tributary_situation_id = value; }
		}
		
		public string Ex_tributary_situation_id {
			get { return _ex_tributary_situation_id; }
			set { _ex_tributary_situation_id = value; }
		}
		
		public string Vendor_id1 {
			get { return _vendor_id1; }
			set { _vendor_id1 = value; }
		}
		
		public string Vendor_id2 {
			get { return _vendor_id2; }
			set { _vendor_id2 = value; }
		}
		
		public string Vendor_id3 {
			get { return _vendor_id3; }
			set { _vendor_id3 = value; }
		}
		
		#endregion
		
		public void clear()
		{
			_id                         = String.Empty;
			_name                       = String.Empty;
		    _short_name                 = String.Empty;
		    _bar_code                   = String.Empty;
		    _code                       = String.Empty;
		    _unit1                      = String.Empty;
		    _unit2                      = String.Empty;
		    _unit3                      = String.Empty;
		    _conversion1                = String.Empty;
		    _conversion2                = String.Empty;
		    _service                    = String.Empty;
		    _rent                       = String.Empty;
		    _service_order              = String.Empty;
		    _image                      = String.Empty;
		    _stock_min                  = String.Empty;
		    _stock_max                  = String.Empty;
		    _weight                     = String.Empty;
		    _duration_time              = String.Empty;
		    _fiscal_nature              = String.Empty;
		    _last_purchase              = String.Empty;
		    _purchase_price             = String.Empty;
		    _sale_price1                = String.Empty;
		    _sale_price2                = String.Empty;
		    _sale_price3                = String.Empty;
		    _nature                     = String.Empty;
		    _control_nserie             = String.Empty;
		    _accept_discount            = String.Empty;
		    _accept_fraction            = String.Empty;
		    _user_bars                  = String.Empty;
		    _active                     = String.Empty;
		    _register_date              = String.Empty;
		    _alteration_date            = String.Empty;
		    _ncm_code                   = String.Empty;
		    _nbm_code                   = String.Empty;
		    _obs                        = String.Empty;
		    _application                = String.Empty;
		    _product_group_id           = String.Empty;
		    _product_sub_group_id       = String.Empty;
		    _product_mark_id            = String.Empty;
		    _product_section_id         = String.Empty;
		    _product_type_id            = String.Empty;
		    _company_id                 = String.Empty;
		    _warehouse_id               = String.Empty;
		    _en_tributary_situation_id  = String.Empty;
		    _ex_tributary_situation_id  = String.Empty;
		    _vendor_id1                 = String.Empty;
		    _vendor_id2                 = String.Empty;
		    _vendor_id3                 = String.Empty;
		}
		
		
		public override void get(System.Data.DataRow dr)
		{
            _id                         = dr["product_id"].ToString();
			_name                       = dr["product_name"].ToString();
		    _short_name                 = dr["product_short_name"].ToString();
		    _bar_code                   = dr["product_bar_code"].ToString();
		    _code                       = dr["product_code"].ToString();
		    _unit1                      = dr["product_unit1"].ToString();
		    _unit2                      = dr["product_unit2"].ToString();
		    _unit3                      = dr["product_unit3"].ToString();
		    _conversion1                = dr["product_conversion1"].ToString();
		    _conversion2                = dr["product_conversion2"].ToString();
		    _service                    = dr["product_is_service"].ToString();
		    _rent                       = dr["product_is_rent"].ToString();
		    _service_order              = dr["product_service_order"].ToString();
		    _image                      = dr["product_image"].ToString();
		    _stock_min                  = dr["product_stock_min"].ToString();
		    _stock_max                  = dr["product_stock_max"].ToString();
		    _weight                     = dr["product_weight"].ToString();
		    _duration_time              = dr["product_duration_time"].ToString();
		    _fiscal_nature              = dr["product_fiscal_nature"].ToString();
		    _last_purchase              = dr["product_last_purchase"].ToString();
		    _purchase_price             = dr["product_purchase_price"].ToString();
		    _sale_price1                = dr["product_sale_price1"].ToString();
		    _sale_price2                = dr["product_sale_price2"].ToString();
		    _sale_price3                = dr["product_sale_price3"].ToString();
		    _nature                     = dr["product_nature"].ToString();
		    _control_nserie             = dr["product_control_nserie"].ToString();
		    _accept_discount            = dr["product_accept_discount"].ToString();
		    _accept_fraction            = dr["product_accept_fraction"].ToString();
		    _user_bars                  = dr["product_user_bars"].ToString();
		    _active                     = dr["product_active"].ToString();
		    _register_date              = dr["product_register_date"].ToString();
		    _alteration_date            = dr["product_alteration_date"].ToString();
		    _ncm_code                   = dr["product_ncm_code"].ToString();
		    _nbm_code                   = dr["product_nbm_code"].ToString();
		    _obs                        = dr["product_obs"].ToString();
		    _application                = dr["product_application"].ToString();
		    _product_group_id           = dr["product_product_group_id"].ToString();
		    _product_sub_group_id       = dr["product_product_sub_group_id"].ToString();
		    _product_mark_id            = dr["product_product_mark_id"].ToString();
		    _product_section_id         = dr["product_product_section_id"].ToString();
		    _product_type_id            = dr["product_product_type_id"].ToString();
		    _company_id                 = dr["product_company_id"].ToString();
		    _warehouse_id               = dr["product_warehouse_id"].ToString();
		    _en_tributary_situation_id  = dr["product_en_tributary_situation_id"].ToString();
		    _ex_tributary_situation_id  = dr["product_ex_tributary_situation_id"].ToString();
		    _vendor_id1                 = dr["product_vendor_id1"].ToString();
		    _vendor_id2                 = dr["product_vendor_id2"].ToString();
		    _vendor_id3                 = dr["product_vendor_id3"].ToString();
		}
		
		
		public override void setGsql()
		{
			gsql.setValue(_id           			  , "product_id");
			gsql.setValue(_name                       , "product_name");
		    gsql.setValue(_short_name                 , "product_short_name");
		    gsql.setValue(_bar_code                   , "product_bar_code");
		    gsql.setValue(_code                       , "product_code");
		    gsql.setValue(_unit1                      , "product_unit1");
		    gsql.setValue(_unit2                      , "product_unit2");
		    gsql.setValue(_unit3                      , "product_unit3");
		    gsql.setValue(_conversion1                , "product_conversion1");
		    gsql.setValue(_conversion2                , "product_conversion2");
		    gsql.setValue(_service                    , "product_is_service");
		    gsql.setValue(_rent                       , "product_is_rent");
		    gsql.setValue(_service_order              , "product_service_order");
		    gsql.setValue(_image                      , "product_image");
		    gsql.setValue(_stock_min                  , "product_stock_min");
		    gsql.setValue(_stock_max                  , "product_stock_max");
		    gsql.setValue(_weight                     , "product_weight");
		    gsql.setValue(_duration_time              , "product_duration_time");
		    gsql.setValue(_fiscal_nature              , "product_fiscal_nature");
		    gsql.setValue(_last_purchase              , "product_last_purchase");
		    gsql.setValue(_purchase_price             , "product_purchase_price");
		    gsql.setValue(_sale_price1                , "product_sale_price1");
		    gsql.setValue(_sale_price2                , "product_sale_price2");
		    gsql.setValue(_sale_price3                , "product_sale_price3");
		    gsql.setValue(_nature                     , "product_nature");
		    gsql.setValue(_control_nserie             , "product_control_nserie");
		    gsql.setValue(_accept_discount            , "product_accept_discount");
		    gsql.setValue(_accept_fraction            , "product_accept_fraction");
		    gsql.setValue(_user_bars                  , "product_user_bars");
		    gsql.setValue(_active                     , "product_active");
		    gsql.setAsDateTime(_register_date              , "product_register_date");
		    gsql.setAsDateTime(_alteration_date            , "product_alteration_date");
		    gsql.setValue(_ncm_code                   , "product_ncm_code");
		    gsql.setValue(_nbm_code                   , "product_nbm_code");
		    gsql.setValue(_obs                        , "product_obs");
		    gsql.setValue(_application                , "product_application");
		    gsql.setValue(_product_group_id           , "product_product_group_id");
		    gsql.setValue(_product_sub_group_id       , "product_product_sub_group_id");
		    gsql.setValue(_product_mark_id            , "product_product_mark_id");
		    gsql.setValue(_product_section_id         , "product_product_section_id");
		    gsql.setValue(_product_type_id            , "product_product_type_id");
		    gsql.setValue(_company_id                 , "product_company_id");
		    gsql.setValue(_warehouse_id               , "product_warehouse_id");
		    gsql.setValue(_en_tributary_situation_id  , "product_en_tributary_situation_id");
		    gsql.setValue(_ex_tributary_situation_id  , "product_ex_tributary_situation_id");
		    gsql.setValue(_vendor_id1                 , "product_vendor_id1");
		    gsql.setValue(_vendor_id2                 , "product_vendor_id2");
		    gsql.setValue(_vendor_id3                 , "product_vendor_id3");
		}
		
	}
	
	public class Products : csharp.common.DefaultList, csharp.common.IList
	{		
		public Products()
		{
			gsql.table = "common.product";
			clear();
		}
		
		public Product get()
		{
			return (Product)items[index];
		}
		
		public Product get(Int32 index)
		{
			return (Product)items[index];
		}
		
		public bool fillList()
		{
			gsql.prepare();
			
			gsql.setValue("", "*");		
			gsql.conditionalWhere = "product_company_id = "+Information.companyId;
			gsql.additionalWhere = "ORDER BY product_name";
			
			return mountList();
		}
		
		public bool mountList()
		{
			int tam;
			if(!gsql.execute())
			{
				return false;
			}
			
			tam = gsql.getRowCount();
			items.Clear();
			
			for(int i = 0; i < tam; i++)
			{
				Product p = new Product();
				p.get(gsql.getRow(i));
				items.Add(p);
			}
			return true;
		}
	}
}
